import { useToggle } from '@vueuse/core'
import { acceptHMRUpdate, defineStore } from 'pinia'

export const useAppStore = defineStore('appStore', () => {
  const [isReload, toggleReload] = useToggle(true)

  /**
   * @description: 重新加载页面
   */
  async function reloadPage() {
    toggleReload(false)

    // eslint-disable-next-line no-undef
    await nextTick()

    toggleReload(true)
  }

  return {
    isReload,
    toggleReload,
    reloadPage,
  }
})

if (import.meta.hot)
  import.meta.hot.accept(acceptHMRUpdate(useAppStore, import.meta.hot))
